window['c']={
	dialogIndex:1,
	//获取url参数
	getQueryString:function (name) {
	    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	    var r = window.location.search.substr(1).match(reg);
	    if (r != null) return unescape(r[2]); return null;
	},
	//获取表格的数据
	getTableData:function(panelId){
		//获取表格元素
		var elemId = "#"+panelId + " .l-grid2 .l-grid-body table";
		c.log("获取表格内容:"+elemId);
		return this.get$TableData($(elemId));
	},
	//获取表格的数据,等待表格填充
	getTableDataWait:function(panelId,callback){
		//获取表格元素
		var elemId = "#"+panelId + " .l-grid2 .l-grid-body table";
		c.waitElemFill(elemId,function($body){
			list = c.get$TableData($body);
			"获取页面表格记录["+list.length+"]条";
			callback();
		});
	},
	get$TableData:function($table){
		var res = [];
		c.log($table);
		//遍历行
		$table.find(".l-grid-row").each(function(index){
			var tmp = [];
			var that = this;
			//遍历列
			$(that).find("td").each(function(index2){
				tmp.push($(this).find("div").html());
			});
			res.push(tmp);
		});
		return res;
	},
	//获取表格的某一个单元格
	getTableCell:function(panelId, rowIndex,colIndex){
		var elemId = t.replaceParams(t.cellId,{
			panelId:panelId,
			row:this.addZero(rowIndex+1,3),
			col:this.addZero(colIndex+2,2)
		});
		return document.getElementById(elemId);
	},
	//前面补0
	addZero:function(v,length){
		var t = v+"";
		while(t.length < length){
			t = "0"+t;
		}
		return t;
	},
	//延时函数，返回计时器的id
	delay:function(time,finished,interval,obj){
		if(time > 0){
			var i = 0;
			var index = setInterval(function(finished,interval){
				i++;
				if(i>=time){
					clearInterval(index);
					interval(i,obj,time);
					finished(obj);
				}else{
					//interval返回值表示是否停止延时
					if(interval(i,obj,time)){
						clearInterval(index);
						finished(obj);
					}
				}
			},1000,finished,interval);
			return index;
		}else{
			finished(obj);
			return -1;
		}
	},
	//关闭延时
	clearDelay:function(index){
		clearInterval(index);
	},
	//等待元素内容填充
	waitElemFill(elemId,callback,timeout){	
		var that = this;
		timeout = timeout||500;
		that.log("检测频率:"+timeout);
		var index = setInterval(function(){
			$elem = $(elemId);
			that.log("检测元素是否填充。。。");
			if($elem.length>0){
				if($elem.html().trim()!=""){
					that.log("检测到元素存在");
					clearInterval(index);
					callback($elem);
				}
			}
		},timeout);
	},
	/** 打印日志-开始 **/
	log:function(msg){
		if(cfg.debug){
			console.log(msg);
		}
	},
	warn:function(msg){
		if(cfg.debug){
			console.warn(msg);
		}
	},
	showInfo:function(msg,caption,btns){
		this.showAlert(caption||"提示","info",msg,btns);
	},
	showWarn:function(msg,caption,btns){
		this.showAlert(caption||"警告","warn",msg,btns);
	},
	showError:function(msg,caption,btns){
		this.showAlert(caption||"错误","error",msg,btns);
	},
	loadingElem:undefined,
	showLoading:function(msg){
		$loading = $(t.replaceParams(t.loading,{Text:msg}));
		c.loadingElem = $loading;
		$("body").append($loading);
	},
	closeLoading:function(){
		c.loadingElem.remove();
	},
	showAlert:function(caption,icon,msg,btns){
		//btns:[{text:"",click:function(){}}]
		btns=btns||[];
		$dialog = $(t.replaceParams(t.alt,{
			idIndex:this.addZero(this.dialogIndex++,3),
			caption:caption,
			icon:icon,
			Message:msg,
			btnOkText:"确定"
		}));
		$("body").append($dialog);
		//设置位置
		var width = $dialog.width();
		var height = $dialog.height();
		var scrollWidth = document.body.scrollWidth;
		var scrollHeight = document.body.scrollHeight;
		$dialog.css("left",(scrollWidth-width)/2+"px");
		$dialog.css("top",(scrollHeight-height)/2+"px");
		//close按钮
		$dialog.find(".l-dialog-winbtns .l-dialog-close").click(function(){
			var id = $(this).parents(".l-dialog").attr("ligeruiid");
			c.closeShow(id);
		});
		//确定按钮
		$dialog.find(".l-dialog-buttons .l-dialog-btn .l-dialog-btn-inner").click(function(){
			var id = $(this).parents(".l-dialog").attr("ligeruiid");
			c.closeShow(id);
		});
		//添加自定义按钮
		for(var index in btns){
			var btn = btns[index];
			$btn = $(t.replaceParams(t.altButton,btn));
			$btn.click(function(){if(btn.click){btn.click();}});
			$dialog.find(".l-dialog-buttons .l-dialog-buttons-inner")
				.append($btn);
		}
		//添加遮罩层-判断有无遮罩层
		if($(".l-window-mask").length>0){
			$(".l-window-mask").css("display","block");
		}else{
			$("body").append($(t.altMask));
		}
		//设置遮罩层的高度
		$(".l-window-mask").css("height",document.body.scrollHeight+"px");
		//对话框头移动事件
		$title = $(".l-dialog-tc .l-dialog-title");
		var down = false;
		var x = 0,y=0;//鼠标原点
		var divLeft = 0;divTop=0;//对话框原位置
		$title.mousedown(function(e){
			down = true;
			x=e.screenX;y=e.screenY;
			divLeft = parseFloat($dialog.css("left").replace("px",""));
			divTop = parseFloat($dialog.css("top").replace("px",""));
		});
		$title.mousemove(function(e){
			if(down){
				$dialog.css("left",((e.screenX-x)+divLeft)+"px");
				$dialog.css("top",((e.screenY-y)+divTop)+"px");
			}
		})
		$title.mouseup(function(e){
			down = false;
		})
	},
	closeShow:function(ligeruiid){
		$(".l-dialog[ligeruiid="+ligeruiid+"]").css("display","none");
		$(".l-window-mask").css("display","none");
	},
	getExcelDate:function(days){
		//excel的天数表示的是从1900-1-1开始到这一天为止的天数，是整数
		//时间戳标识的是从1970年01月01日08时00分00至这一天的毫秒数
		/************将excel的days转为时间戳*************/
		if(typeof(days)=="number"){
			//将days转为毫秒数
			//var mm = (days-2)*24*60*60*1000;
			//转为时间戳（毫秒数加上1900-1-1的时间戳）
			//var time = mm+new Date("1900-1-1").getTime();
			//return new Date(time);
			return new Date(1900,0,days-1);
		}else{
			return new Date(days);
		}
	}
	/** 打印日志-结束 **/
}
 